package com.example.mybubbleshooter;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Queue;

public class Global {
	public final static int EASY=0;
	public final static int MEDIUM=1;
	public final static int HARD=2;
	public static int height;
	public static int width;
	public static int currentLevel=EASY;
	final static int MAX_EVEN_LINE_NUMBER_OF_BALLS = 8;
	final static int MAX_ODD_LINE_NUMBER_OF_BALLS = 7;
	public static int score=0;
	public static float ballRadius=0;
	public static int numOfInitializedBalls=30;
	public static Queue<Ball> pool;
	public static Ball []defaultBallsArray;
	public static Queue<Ball> currentStaticBalls;
	public static Ball map[][];
	public static int NUMBER_OF_ROWS=16;
	public static float misselX;
	public static float misselY;
	public static float columnIndexes[][];
	public static float layerIndex[];
	public static int   maxLayer;
	public static boolean soundEnabled;
	public static boolean vibertaeEnabled;
	public static int per;
	public static int  oe;
	public static void initGlobal()
	{
		per=0;
		oe=0;
		int margin = getFirstBallPosition(Global.width);
		Global.ballRadius = ((Global.width - margin) / Global.MAX_EVEN_LINE_NUMBER_OF_BALLS) / 2;
		Global.pool = new LinkedList<Ball>();
		currentStaticBalls=new LinkedList<Ball>();
		int number=(int)((height/(ballRadius*2))*8);
		defaultBallsArray=Ball.getDefaultBalls();
		Ball.addBallsToPool(number-numOfInitializedBalls);
		map=new Ball[NUMBER_OF_ROWS][MAX_EVEN_LINE_NUMBER_OF_BALLS];
		misselX=Global.width/2.0f;
		misselY=Global.height-Global.ballRadius;
		columnIndexes=new float[2][];
		columnIndexes[0]=new float[8];
		columnIndexes[1]=new float[7];
		layerIndex=new float[NUMBER_OF_ROWS];
		
		for(int i=0;i<8;i++)
		{
			columnIndexes[0][i]=2.0f*i*ballRadius;
		}
		for(int i=0;i<7;i++)
		{
			columnIndexes[1][i]=2.0f*i*ballRadius+ballRadius;
		}
		
		for(int i=0;i<layerIndex.length;i++)
		{
			layerIndex[i]=2.0f*i*ballRadius;
		}
		
	}
	public static void addToPool(Ball b)
	{
		b.setCenterX(0);
		b.setCenterY(0);
		b.setDx(0);
		b.setDy(0);
		b.setFalling(false);
		b.setStatic(false);
		Global.pool.add(b);
	}
	private static int getFirstBallPosition(int width) {
		int margin = 0;
		while (width % Global.MAX_EVEN_LINE_NUMBER_OF_BALLS != 0)
			margin++;
		return margin;
	}

}

